import React from 'react';
import { Button, message, Form, Input } from 'antd';
import RightTitle from '@/util/RightTitle'
import axios from 'axios'
import { useNavigate } from 'react-router-dom'


const Action_list: React.FC = () => {

  const [messageApi, contextHolder] = message.useMessage()

  const navigate = useNavigate()

  const onFinish = (values: any) => {

    (async () => {
      let url = 'http://localhost:2001/api/admin';
      const res = await axios.post(url, values)
      // console.log(res.data);
      const { status, msg } = res.data
      if (status === 200) {
        messageApi.open({
          type: 'success',
          content: msg,
          duration: 1.2,
        });
        setTimeout(() => {
          navigate('/afeng/user_control/userlist')
        },1500)
      } else {
        messageApi.open({
          type: 'warning',
          content: msg,
          duration: 1.2,
        });
      }
    })()

  };


  return (
    <>
      <RightTitle name='添加管理员' />
      {contextHolder}
      <Form
        name="basic"
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
        style={{ maxWidth: 400 }}
        initialValues={{ remember: true }}
        onFinish={onFinish}
        autoComplete="off"
      >
        <Form.Item
          label="用户名"
          name="account"
          rules={[{ required: true, message: '请输入用户名' }]}
        >
          <Input />
        </Form.Item>
        <Form.Item
          label="密码"
          name="passwd"
          rules={[{ required: true, message: '请输入密码' }]}
        >
          <Input.Password />
        </Form.Item>

        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
          <Button type="primary" htmlType="submit" >
            添加
          </Button>
        </Form.Item>
      </Form>
    </>
  )
}

export default Action_list;